<!DOCTYPE html>
<html>
<head>
    <title>创建新标签</title>
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/static/css/bootstrap-icons.css">
    <link rel="shortcut icon" href="/static/images/favicon.ico">
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
            background-color: #f8f9fa;
        }
        .centered-container {
            width: 100%;
            max-width: 500px;
            padding: 0 15px;
        }
        .create-card {
            width: 100%;
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
    </style>
</head>
<body>
    <!-- 替换Bootstrap的container为自定义容器 -->
    <div class="centered-container">
        <div class="card create-card">
            <div class="card-body">
                <h3 class="card-title text-center mb-4">创建新标签</h3>
                <form id="createTagForm">
                    <div class="mb-3">
                        <label for="tagName" class="form-label">标签名称</label>
                        <input type="text" class="form-control" id="tagName" required>
                        <div class="invalid-feedback">请输入标签名称</div>
                    </div>
                    <div class="d-grid gap-2">
                        <button type="submit" class="btn btn-primary">创建标签</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        document.getElementById('createTagForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const tagName = document.getElementById('tagName').value.trim();
            if (!tagName) {
                document.getElementById('tagName').classList.add('is-invalid');
                return;
            }
            
            document.getElementById('tagName').classList.remove('is-invalid');
            
            fetch('/create-tag', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({
                    title: tagName
                })
            })
            .then(response => response.json())
            .then(data => {
                if (data.status === 'success') {
                    window.location.href = '/?id=' + data.id;
                } else {
                    alert('创建失败: ' + (data.error || '未知错误'));
                }
            })
            .catch(error => {
                console.error('Error:', error);
                alert('创建标签时出错');
            });
        });
    </script>
</body>
</html>